<div class="content-wrapper" [@routerTransition]>
    <sub-header idName="Administration.CustomConfig" [title]="'CustomConfig' | localize">
        <div role="actions">
            <button (click)="create()" class="btn btn-primary blue mr-1"  
                *ngIf="'Pages.Administration.CustomConfigs.Create'| permission">
                <i class="fa fa-plus"></i> {{"CreateNew" | localize}}
            </button>
            <button (click)="delete()" class="btn btn-warning mr-1" 
                *ngIf="'Pages.Administration.CustomConfigs.Delete'| permission">
                <i class="fa fa-trash"></i>{{"Delete" | localize}}
            </button>
            <button (click)="changeState(true)" *ngIf="'Pages.Administration.CustomConfigs.Edit'| permission"
             class="btn btn-primary blue mr-1">
            <i class="fa fa-book"></i> {{"Release" | localize}}
            </button>
            <button (click)="changeState(false)" *ngIf="'Pages.Administration.CustomConfigs.Edit'| permission"
             class="btn btn-warning mr-1">
            <i class="fa fa-reply"></i> {{"CancelRelease" | localize}}
            </button>
            <button (click)="config()" class="btn btn-sm btn-warning mr-1" 
                *ngIf="'Pages.Administration.CustomConfigs.ConfigFileEdit'| permission">
                <i class="fa fa-cog"></i>{{"ConfigFile" | localize}}
            </button>
            <button (click)="generalConfigFile()" class="btn btn-primary blue" 
                *ngIf="'Pages.Administration.CustomConfigs.ConfigFileEdit'| permission">
                <i class="fa bi-recycle"></i>自动生成</button>
        </div>
    </sub-header>
    <!-- /.content-header -->
    <!-- Main content -->
    <section class="content d-flex flex-column flex-column-fluid">
        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">
                    <form class="form" autocomplete="new-password">
                        <div>
                            <div class="row align-items-center mb-4">
                                <div class="col-xl-12">
                                    <div class="form-group m-form__group align-items-center">
                                        <div class="input-group">
                                            <input [(ngModel)]="filterText" name="filterText" autoFocus
                                                   class="form-control m-input" [placeholder]="l('SearchWithThreeDot')"
                                                   type="text">
                                            <div class="input-group-append">
                                                <button (click)="getListData()" class="btn btn-default"
                                                        type="submit">
                                                    <i class="icon-magnifier"
                                                       [attr.aria-label]="l('Search')"></i>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>

                    <div class="row align-items-center">
                        <!--<Primeng-TurboTable-Start>-->
                        <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <p-table #dataTable sortMode="multiple" (onLazyLoad)="getListData($event)"
                                [value]="primengTableHelper.records"
                                rows="{{primengTableHelper.defaultRecordsCountPerPage}}" [paginator]="false"
                                [lazy]="true" 
                                [responsive]="primengTableHelper.isResponsive"
                                [resizableColumns]="primengTableHelper.resizableColumns"
                                [(selection)]="selectedDatas" 
                                dataKey="id" 
                                selectionMode="multiple">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th style="width:38px">
                                            <p-tableHeaderCheckbox></p-tableHeaderCheckbox>
                                        </th>
                                        <th style="width: 200px">
                                            {{"Name" | localize}}
                                        </th>
                                        <th style="width: 200px">
                                            {{"Description" | localize}}
                                        </th>
                                        <th style="width: 120px">
                                            {{'DataType' | localize}}
                                        </th>
                                        <th style="width: 160px" >
                                            Key
                                        </th>
                                        <th style="width:120px">
                                            {{'ReleaseState' | localize}}
                                        </th>
                                        <th style="width: 160px" >
                                            {{"MotifyTime" | localize}}
                                        </th>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record="$implicit">
                                    <tr>
                                        <td style="width: 38px">
                                            <p-tableCheckbox [value]="record" (click)="$event.stopPropagation()"></p-tableCheckbox>
                                         </td>
                                        <td style="width: 200px">
                                            <span class="p-column-title">{{"Name" | localize}}</span>
                                            <a title="{{record.name}}" href="javascript:void(0)" (click)="editConfig(record)">{{record.name}}</a>
                                        </td>
                                        <td style="width: 200px">
                                            <span class="p-column-title"> {{"Description" | localize}}</span>
                                            <span title="{{record.description}}">
                                                {{record.description | stringTruncate: 35}}
                                            </span>
                                        </td>
                                        <td style="width: 120px">
                                            <span class="p-column-title"> {{'DataType' | localize}}</span>
                                            {{record.dataType}}
                                        </td>
                                        <td style="width: 160px">
                                            {{record.key}}
                                        </td>
                                        <td style="width: 120px">
                                            <span class="p-column-title"> {{'ReleaseState' | localize}}</span>
                                            <span class="label label-success label-inline" *ngIf="record.isActive">{{'Yes' | localize}}</span>
                                            <span class="label label-dark label-inline" *ngIf="!record.isActive">{{'No' | localize}}</span>
                                        </td>
                                        <td style="width: 160px">
                                            <span class="p-column-title"> {{"MotifyTime" | localize}}</span>
                                            {{(record.lastModificationTime?record.lastModificationTime:record.creationTime) | luxonFormat:'yyyy-MM-dd HH:mm:ss'}}
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
                                {{'NoData' | localize}}
                            </div>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getListData($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage"
                                    [showCurrentPageReport]="true"
                                    [currentPageReportTemplate]="'TotalRecordsCount' | localize:primengTableHelper.totalRecordsCount">
                                </p-paginator>
                            </div>
                        </div>
                        <!--<Primeng-TurboTable-End>-->
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<custom-config-modal #editConfigModal (callback)="reloadPage()"></custom-config-modal>
<json-editor-modal #jsonEditorModal (callback)="configSave($event)"></json-editor-modal>
